package data.set.implementation;

import java.util.Random;

import data.set.OfflineSet;
import data.set.OfflineSetIterator;


/**
 * Builds an OfflineSetIterator which is a sampling of another set
 * @author guillaumes
 *
 * @param <X>
 */
public class OfflineSetIteratorRandomInfinite<X> implements OfflineSetIterator<X>
{
	private OfflineSet<X> set;
	private OfflineSetIterator<X> iterator;
	
	
	private Random rand;
	
	
	private static int intervalle=1000;
	/**
	 * 
	 * @param iterator
	 * @param proba
	 */
	public OfflineSetIteratorRandomInfinite(OfflineSet<X> set, Random rand)
	{
		this.set=set;
		this.rand = rand;
		iterator = set.inputsetiterator();

		go();
	}
	
	private void go()
	{
		int i = rand.nextInt(intervalle)+1;
		int cpt=0;
		while( cpt<i)
		{
			cpt++;
			if(!iterator.hasNext())
				iterator = set.inputsetiterator(); // retour au debut
			
			iterator.next();
			
		}
		
	}
	
	
	public int getCurrentId() {
//		System.out.println("new ID: "+ iterator.getCurrentId());
		return iterator.getCurrentId();
	}

	
	public X getCurrentObject() {
		return iterator.getCurrentObject();
	}

	
	public boolean hasNext() {
		return true;
	}

	
	public void next() {
		
		go();
	}
}
